<%@ page isELIgnored="false" contentType="text/html;charset=UTF-8" language="java" pageEncoding="utf-8"%>
<html>
<head>
    <title>编辑简历</title>

    <script type="text/javascript" src="/js/jquery.min.js"></script>

    <% String id = request.getParameter("id"); %>

    <script>
        function submit() {

            var name = $("#name").val();
            var address = $("#address").val();
            var phone = $("#phone").val();

            if (!<%= id %>) {
                var allData={
                    name:name,
                    address:address,
                    phone : phone
                }

                // 发送ajax请求
                $.ajax({
                    url: '/resume/save',
                    type: 'POST',
                    data: JSON.stringify(allData),
                    contentType: 'application/json;charset=utf-8',
                    dataType: 'json',
                    success: function (data) {
                        if (data.code == 200){
                            alert("新增成功");
                            window.opener.location.reload();
                            window.close();
                        }else {
                            alert("新增失败");
                        }

                    }
                })
            }else {
                var allData={
                    id:<%= id  %>,
                    name:name,
                    address:address,
                    phone : phone
                }

                // 发送ajax请求
                $.ajax({
                    url: '/resume/update',
                    type: 'POST',
                    data: JSON.stringify(allData),
                    contentType: 'application/json;charset=utf-8',
                    dataType: 'json',
                    success: function (data) {
                        if (data.code == 200){
                            alert("更新成功");
                            window.opener.location.reload();
                            window.close();
                        }else {
                            alert("更新失败");
                        }

                    }
                })
            }

        }
    </script>

    <style>
        div{
            padding:10px 10px 0 10px;
        }
    </style>
</head>
<body>

<form>
    <td>姓名：</td>
    <input type="text" id="name" value=""/>
    <br>
    <td>地址：</td>
    <input type="text" id="address" value=""/>
    <br>
    <td>电话：</td>
    <input type="text" id="phone" value=""/>
</form>

    <input type="button" value="保存" id="btn_1" onclick="submit()"/>


</body>
</html>
